/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-1-10 下午2:20 Created by lyyang
 */
package com.jade.bss.business.groupon.impl;

import java.util.List;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.jade.bss.business.groupon.Groupon;
import com.jade.bss.business.groupon.GrouponDao;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.criterion.sql.SqlUtils;
import com.jade.framework.base.util.PagingList;

/**
 * 团购券dao,jpa实现
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-1-10 下午2:20
 */
@Named ("ags_grouponDao")
public class JpaGrouponDao
        implements GrouponDao
{

    @PersistenceContext (unitName = "default")
    protected EntityManager entityManager;

    public void add(Groupon groupon)
    {
        entityManager.persist(groupon);
    }

    public void update(Groupon setting)
    {
        entityManager.merge(setting);
    }

    public void remove(Groupon groupon)
    {
        entityManager.remove(groupon);
    }

    public Groupon get(long id)
    {
        return entityManager.find(Groupon.class, id);
    }

    public List<Groupon> list(Criteria criteria)
    {
        String sql = "SELECT groupon FROM Groupon groupon";
        return SqlUtils.sqlQueryWithoutCount(sql, entityManager, criteria);
    }

    public PagingList<Groupon> query(Criteria criteria)
    {
        String sql = "SELECT groupon FROM Groupon groupon";
        return SqlUtils.sqlQuery(sql, entityManager, criteria);
    }
}
